package com.yang.system.domain.orgMng.org;

import com.yang.system.application.orgMng.orgService.OrgResponse;
import com.yang.system.domain.orgMng.org.validator.OrgValidator;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

//已调整使用builder模式 未使用OrgFactory
@Component
public class OrgFactory {
    private final OrgValidator validator;

    @Autowired
    public OrgFactory(OrgValidator validator) {
        this.validator = validator;
    }

    public Org build(OrgResponse request, Long useId) {
        validator.validate(request);
        return buildOrg(request,useId);
    }

    private Org buildOrg(OrgResponse request, Long useId) {
        // 将DTO的值赋给领域对象...
        Org org = new Org();
        BeanUtils.copyProperties(request, org);
        org.setCreatedBy(useId);
        return org;
    }
}
